package Offer.offer2017;

/**
 * 将公司员工年龄排序
 * Created by 雷文康 on 2017/12/28.
 */
public class Test07b {
    public static void main(String[] args) {
        int[] ages = {5,3,7,15,7,2,6,3,6,2,66,7,2,78,24,23,67};
        sortAge(ages);
        for (int i = 0; i < ages.length; i++) {
            System.out.println(ages[i]);
        }
    }
    public static void sortAge(int[] ages) {
        if (ages == null || ages.length == 0) {
            return;
        }
        //最大年龄假设为99，年龄范围为0-99
        int maxAge = 99;
        int[] timesOfAge = new int[maxAge + 1];
        for (int i = 0;i <ages.length; i++) {
            int age = ages[i];
            timesOfAge[age]++;
        }
        int index = 0;
        for(int i = 0; i <= maxAge; i++) {
              for (int j = 0; j < timesOfAge[i]; j++){
                  ages[index++] = i;
              }
        }
    }
}
